function lookupdate(id) {
    $.getJSON("/document/lookbyid", "id=" + id, function (dataA) {
        var img = dataA.type;
        if (img == 1) {
            img = "<img src='../images/document/jia2.png'>";
        } else if (img == 2) {
            img = "<img src='../images/document/doc.png'>";
        } else if (img == 3) {
            img = "<img src='../images/document/txt.png'>";
        }else if (img == 4) {
            img = "<img src='../images/document/jpg.png'>";
        }else if (img == 5) {
            img = "<img src='../images/document/pdf.png'>";
        }else if (img == 6) {
            img = "<img src='../images/document/xls.png'>";
        }else if (img == 7) {
            img = "<img src='../images/document/zip.png'>";
        }

        let date = new Date(dataA.createDate);
        var m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
        var d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())

        layer.open({
            type: 1,
            area: ['340px', '340px'],
            shadeClose: true, //点击遮罩关闭
            btnAlign: "c",
            content: ' <div id="box"><div id="main"><table border="0"><th style="width: 120px; text-align: right;">名称：</th><td><input style="text-align: center; margin-top: 5px;color: darkgray;" type="text" class="layui-input ctitle" placeholder="' + dataA.title + '" value=""/></td><tr><th style="text-align: right;height: 50px">类型：</th><td style="text-align: center;">' + img + '</td></tr><tr><th style="height:30px; text-align: right;">所在部门：</th><td style="text-align: center;">' + dataA.department.departmentname + '</td></tr><tr><th style="height:50px; text-align: right;">创建时间：</th><td style="text-align: center;">' + date.getFullYear() + "-" + m + "-" + d + '</td></tr></table></div>',
            btn: ["保存", "关闭"],
            btn1: function () {
                let title = $(".ctitle").val();
                let id = dataA.id;
                console.log("按钮中id的值++++++++++++++++" + id);
                console.log("按钮中title的值**************" + title);
                if (title == "" | title == null) {
                    layer.tips('所填内容不能为空！', '.ctitle');
                    return;
                }
                let json = {
                    title: title,
                    id: id,
                }
                $.ajaxSettings.async = false;
                $.post("/document/updatebyid", json, function (data) {
                    if (data > 0) {
                        layer.alert('修改数据成功！', {
                            skin: 'layui-layer-lan'
                            , closeBtn: 0
                            , anim: 3 //动画类型
                        });
                        examine()
                        setTimeout("window.location.href='/document/listdocument'", 50000);
                    } else {
                        layer.tips('修改数据失败！', '.ctitle');
                    }
                })
                $.ajaxSettings.async = true;
            }
        });

    })
};

function reupdate(id) {
    layer.confirm('确定要删除吗？',
        {
            btn: ['删除', '取消'],
            yes: function () {
                $.ajaxSettings.async = false;
                $.post("/document/reupdate", "id=" + id, function (data) {
                    if (data > 0) {
                        layer.alert('删除数据成功！', {
                            skin: 'layui-layer-lan'
                            , closeBtn: 0
                            , anim: 3 //动画类型
                        });
                        examine()
                        setTimeout("window.location.href='/document/listdocument'", 50000);
                    } else {
                        layer.alert('删除数据失败！', {
                            skin: 'layui-layer-lan'
                            , closeBtn: 0
                            , anim: 3 //动画类型
                        });
                        examine()
                    }
                })
                $.ajaxSettings.async = true;
            }
        })


}

function orderby(id) {
    location.href = "/document/orderby?id=" + id;

}

function addfiles() {
    let id = $(".aid").val();
    console.log(id+"-------------------")
    layer.open({
        content:'/document/tofiles?id='+id,
        type:2,
        area: ['340px', '340px'],
        btnAlign: "c",
        btn: ["关闭"],
        btn1:function () {
            location.reload();
        }
    })
}

function addfolder() {
    let uid = $(".uid").val();
    if (uid == 1){
        path = "文档管理/IT部/";
    }else if (uid == 2){
        path ="文档管理/销售部/";
    }else if (uid==3){
        path ="文档管理/人事部/";
    }else if (uid==4){
        path ="文档管理/研发部/";
    }else if (uid==5){
        path ="文档管理/行政部/";
    }
        layer.open({
            type: 1,
            area: ['370px', '255px'],
            btnAlign: "c",
            shadeClose: true, //点击遮罩关闭
            content: ' <div id="box"><div id="main"><table border="0"><th style="width: 120px; text-align: right;">名称：</th><td><input style="text-align: center; margin-top: 5px;color: darkgray;" type="text" class="layui-input name" value=""/></td><tr><tr><th style="height:40px; text-align: right;">所在位置：</th><td style="text-align: center;" class="path">'+path+'</td></tr></table></div>',
            btn: ["保存", "关闭"],
            btn1: function () {

                var name = $(".name").val();
                let parentId = null;
                let dp_id = $(".dp_id").val();
                let path = $(".path").text();
                if (name == "" | name == null) {
                    layer.tips('所填内容不能为空！', '.name');
                    return;
                }
                $.getJSON("/document/repeatName", "title=" + name, function (dataD) {
                    if (dataD) {
                        layer.tips('列表已有相同文件名！请更换', '.name');
                        return;
                    } else {
                        let json = {
                            title: name,
                            parentId: parentId,
                            dp_id: dp_id,
                            path: path
                        }

                        $.ajaxSettings.async = false;
                        $.post("/document/addfile", json, function (dataC) {
                            if (dataC > 0) {
                                layer.alert('添加文件夹成功！', {
                                    skin: 'layui-layer-lan'
                                    , closeBtn: 0
                                    , anim: 3 //动画类型
                                });
                                examine()

                                setTimeout("window.location.href='/document/listdocument'", 50000);
                            } else {
                                layer.alert('添加文件夹失败！', {
                                    skin: 'layui-layer-lan'
                                    , closeBtn: 0
                                    , anim: 3 //动画类型
                                });
                                examine()
                            }
                        })
                        $.ajaxSettings.async = true;
                    }

                })
            }
        });


}

function examine() {
    sumPage = 1;
    currentPage = 1;
    pageSize = 5;
    console.log("总页数：------------------------" + pages)
    console.log("当前页：--------------------------" + pageNum)
        $(".maininfo").html("");
        var json = {
            currentPage:pageNum,
            pageSize:pageSize,
            title: $(".cname").val().trim(),
            type: $(".filetype").val(),
            createDate: $(".createDate").val()
        }
        console.log("json中的数据======================================"+JSON.stringify(json))
        $.ajaxSettings.async = false;
        $.getJSON("/document/orderinfo", json, function (data) {
            currentPage = data.pageNum;
            sumPage = data.pages;
                console.log("传到js中数据----------------------------" + JSON.stringify(data));
            if (data == "") {
                alert("没有查到该数据！", "", function () {
                }, {type: 'question', confirmButtonText: 'OK'});
            }
            $(data.list).each(function (i, v) {
                console.log("传到js遍历的数据----------------------------" + data.v);
                var img = v.type;
                if (img == 1) {
                    img = "<img src='../images/document/jia2.png'>";
                } else if (img == 2) {
                    img = "<img src='../images/document/doc.png'>";
                } else if (img == 3) {
                    img = "<img src='../images/document/txt.png'>";
                }else if (img == 4) {
                    img = "<img src='../images/document/jpg.png'>";
                }else if (img == 5) {
                    img = "<img src='../images/document/pdf.png'>";
                }else if (img == 6) {
                    img = "<img src='../images/document/xls.png'>";
                }else if (img == 7) {
                    img = "<img src='../images/document/zip.png'>";
                }
                let date = new Date(v.createDate);
                var m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
                var d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
                var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours())
                var min = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
                var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
                if (v.type != 1){
                    var btn = "<input type=\"button\" style=\"height: 30px;line-height: 30px;\" class=\"layui-btn layui-btn-normal\" onclick='down(\""+v.newfilename+ "\")' value=\"下载\"> ";
                    var check = "<button style=\"height: 30px;line-height: 30px;\" class=\"layui-btn\" onclick='che(\"" +v.path +"\")'>查看</button>";
                    var title = "<p>" + v.title + "</p>";
                }else {
                    btn = "";
                    check = "";
                    var title = "<p onclick='orderby(" + v.id + ")'>" + v.title + "</p>";
                }

                $(".maininfo").append("<tr height=\"50\">\n" +
                    "      <td align=\"center\">"+(i+1)+"</td>"+
                    "      <td colspan=\"2\" class=\"place\">"+title+"</td>\n" +
                    "       <td style=\"height: 60px!important;\" align=\"center\">" + img + "</td>\n" +
                    "        <td width=\"100\" class=\"place\">" + v.department.departmentname + "</td>\n" +
                    "       <td width=\"150\" class=\"place\">" + date.getFullYear() + "-" + m + "-" + d +" "+ h +":"+min+":"+s+"</td>\n" +
                    "       <td width=\"350\" class=\"place\"><input type=\"button\" style=\"height: 30px;line-height: 30px;margin-left: 15px;\" class=\"layui-btn layui-btn-normal\" onclick='lookupdate(" + v.id + ")' value=\"修改\">     <input type=\"button\" style=\"height: 30px;line-height: 30px;\" class=\"layui-btn layui-btn-danger\" onclick='reupdate(" + v.id + ")' value=\"删除\">" +
                    "       <span style=\"margin-left: 10px\">"+btn+"</span>"+
                    "       <span style=\"margin-left: 10px\">"+check+"</span>"+
                    "</td>\n" +
                    "    </tr>")
            })
        })
        $.ajaxSettings.async = true;
        if (sumPage==0){
            sumPage=1;
        }
    $(".yeshu").text("第" + currentPage + "页 / 共" + sumPage + "页")

}

function down(title) {
    console.log("新名字是--------------------------------------------"+title);
    location.href = "/document/download?title=" + title;
}
function che(path){
    location.href="http://"+path;
}

$(function(){
    //$('table tr:not(:first)').remove();
    var len = $('table tr').length;
    for(var i = 2;i<len;i++){
        var num =$('table tr:eq('+i+') td:first').text(i-1-1);
    }

});

function echarts() {
    layer.open({
        content:'/echarts/ech',
        type: 2,
        area: ['740px', '440px'],
        btnAlign: "c",
        btn: ["关闭"],
    });
}
